package org.dinqy;

import javax.persistence.EntityManager;

import org.dinqy.impl.QueryExecutorImpl;
import org.dinqy.impl.WhereNode;
import org.dinqy.syntax.Finder;

/**
 * Main class for doing lookups.
 * 
 * @author armandino (at) gmail.com
 */
public final class Dinqy {
    private final EntityManager entityManager;

    public Dinqy(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    public <T> Finder<T> finder(Class<T> entity) {
        final WhereNode<T> whereNode = new WhereNode<T>();
        
        final QueryExecutor<T> queryExecutor =
            new QueryExecutorImpl<T>(whereNode, entityManager);
        
        whereNode.setQueryExecutor(queryExecutor);
        whereNode.setEntityClass(entity);
        return whereNode;
    }

}

